package com.ossean.match.matchprocess;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ossean.match.dao.ProjectDao;
import com.ossean.match.dao.RelativeMemoDao;
import com.ossean.match.dao.TagDao;

@Component("newprjmonitor")
public class NewPrjMonitor {

	@Resource
	private TagDao tagDao;
	@Resource
	private ProjectDao projectDao;
	@Resource
	private RelativeMemoDao memoDao;

	MatchIncrement matchIncrement = null;

	public void setMatchIncrement(MatchIncrement matchIncrement) {
		this.matchIncrement = matchIncrement;
	}

	public void run() {
		int newPrjCount = projectDao.getNewPrjCount();
		int lastMemoId = memoDao.getLastMemoId();
		if (newPrjCount > 0) {
			matchIncrement.setNewPrjComing(true);
		} else {
			matchIncrement.setNewPrjComing(false);
		}
		if (lastMemoId > matchIncrement.getMemoHistory()) {
			matchIncrement.setNewMemoComing(true);
		} else {
			matchIncrement.setNewMemoComing(false);
		}
		
		if (!matchIncrement.isNewMemoComing()&&!matchIncrement.isNewPrjComing()) {
			matchIncrement.setSleepTime(30000);
		}else {
			matchIncrement.setSleepTime(0);
		}
	}
	
}
